package com.wlj.security.app.social;

import com.wlj.security.core.social.WljSpringSocialConfigurer;
import org.apache.commons.codec.binary.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * spring所有bean初始化前后都调用下面两个方法
 */
@Component
public class SpringSocialConfigurerPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String s) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        //将wljSocialSecurityConfig初始化的signUpUrl
        if(StringUtils.equals(beanName,"wljSocialSecurityConfig")){
            WljSpringSocialConfigurer config = (WljSpringSocialConfigurer) bean;
            //social登录时，发现是第一次登录时，本该跳到注册页的地址，但这里修改为一个社交注册接口地址，成功后返回401,然后再引导用户去注册页
            config.signupUrl("/social/signUp");
            return config;
        }
        return bean;
    }
}
